package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.localbean.LocalMoreProductInfo;
import com.wgts.wgts.localbean.LocalUserList;
import com.wgts.wgts.localbean.LocalWinner;
import com.wgts.wgts.localbean.ProductImages;
import com.wgts.wgts.mvp.model.IMoreMoreGoodInfoActivityModel;
import com.wgts.wgts.mvp.presenter.IMoreMoreGoodInfoActivityPresenter;
import com.wgts.wgts.mvp.view.IMoreMoreGoodInfoActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.req.MoreMoreGoodsInfoReq;
import com.wgts.wgts.netmodle.resp.MoreMoreGoodsInfoEntity;
import com.wgts.wgts.netmodle.resp.MoreMoreOpenEntity;

import java.util.ArrayList;

public class MoreMoreGoodInfoActivityPresenter implements IMoreMoreGoodInfoActivityPresenter {

    private IMoreMoreGoodInfoActivityModel model;

    private IMoreMoreGoodInfoActivityView view;

    public MoreMoreGoodInfoActivityPresenter(IMoreMoreGoodInfoActivityModel model, IMoreMoreGoodInfoActivityView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void moreMoreActionInfo(int drawId) {
        MoreMoreGoodsInfoReq req = new MoreMoreGoodsInfoReq();
        req.drawId = drawId;
        model.moreMore(req, new HttpResultSubscriber<MoreMoreGoodsInfoEntity>() {
            @Override
            public void onSuccess(MoreMoreGoodsInfoEntity entity) {
                LocalMoreProductInfo localMoreProductInfo = new LocalMoreProductInfo();
                localMoreProductInfo.productId = entity.productId;
                localMoreProductInfo.productName = entity.productName;
                localMoreProductInfo.productStandard = entity.productStandard;
                localMoreProductInfo.restTime = entity.restTime;
                localMoreProductInfo.sharePath = entity.sharePath;
                localMoreProductInfo.shareCount = entity.shareCount;
                localMoreProductInfo.status = entity.status;
                localMoreProductInfo.drawNumber = entity.drawNumber;
                localMoreProductInfo.productPrice = entity.productPrice;
                localMoreProductInfo.relation = entity.relation;
                localMoreProductInfo.productSmallImage = entity.productSmallImage;
                localMoreProductInfo.productSubtitle = entity.productSubtitle;

                LocalWinner localWinner = new LocalWinner();
                localWinner.userId = entity.userId;
                localWinner.userImage = entity.userImage;
                localWinner.userNickName = entity.userNickName;
                localWinner.winningTime = entity.winningTime;
                localWinner.userNickName = entity.winnerUserNickName;
                localWinner.userImage = entity.winnerUserImage;
                localWinner.userId = entity.winnerUserId;
                localMoreProductInfo.shareId = String.valueOf(entity.shareId);

                ArrayList<ProductImages> productBanner = new ArrayList<>();

                for(MoreMoreGoodsInfoEntity.ProductImage item : entity.productImages){
                    ProductImages banner = new ProductImages();
                    banner.filePath = item.filePath;
                    productBanner.add(banner);
                }

                ArrayList<ProductImages> productBig = new ArrayList<>();

                for(MoreMoreGoodsInfoEntity.ProductBigImage item : entity.productBigImage){
                    ProductImages bigImg = new ProductImages();
                    bigImg.filePath = item.filePath;
                    productBig.add(bigImg);
                }

                ArrayList<LocalUserList> userLists = new ArrayList<>();

                for (MoreMoreGoodsInfoEntity.UserList item : entity.userList){
                    LocalUserList localUserList = new LocalUserList();
                    localUserList.attendTime = item.winningTime;
                    localUserList.userImage = item.userImage;
                    localUserList.userNickName = item.userNickName;
                    userLists.add(localUserList);
                }



                view.productResult(productBanner, productBig, localMoreProductInfo, userLists, localWinner);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void launchMoreMoreAction(int shareId) {
        model.launchMoreMoreAction(shareId, new HttpResultSubscriber<MoreMoreGoodsInfoEntity>() {
            @Override
            public void onSuccess(MoreMoreGoodsInfoEntity entity) {
                LocalMoreProductInfo localMoreProductInfo = new LocalMoreProductInfo();
                localMoreProductInfo.productId = entity.productId;
                localMoreProductInfo.productName = entity.productName;
                localMoreProductInfo.productStandard = entity.productStandard;
                localMoreProductInfo.restTime = entity.restTime;
                localMoreProductInfo.sharePath = entity.sharePath;
                localMoreProductInfo.shareCount = entity.shareCount;
                localMoreProductInfo.status = entity.status;
                localMoreProductInfo.drawNumber = entity.drawNumber;
                localMoreProductInfo.productPrice = entity.productPrice;
                localMoreProductInfo.relation = entity.relation;
                localMoreProductInfo.productSmallImage = entity.productSmallImage;
                localMoreProductInfo.productSubtitle = entity.productSubtitle;

                LocalWinner localWinner = new LocalWinner();
                localWinner.userId = entity.userId;
                localWinner.userImage = entity.userImage;
                localWinner.userNickName = entity.userNickName;
                localWinner.winningTime = entity.winningTime;
                localWinner.userNickName = entity.winnerUserNickName;
                localWinner.userImage = entity.winnerUserImage;
                localWinner.userId = entity.winnerUserId;

                localMoreProductInfo.shareId = String.valueOf(entity.shareId);

                ArrayList<ProductImages> productBanner = new ArrayList<>();

                for(MoreMoreGoodsInfoEntity.ProductImage item : entity.productImages){
                    ProductImages banner = new ProductImages();
                    banner.filePath = item.filePath;
                    productBanner.add(banner);
                }

                ArrayList<ProductImages> productBig = new ArrayList<>();

                for(MoreMoreGoodsInfoEntity.ProductBigImage item : entity.productBigImage){
                    ProductImages bigImg = new ProductImages();
                    bigImg.filePath = item.filePath;
                    productBig.add(bigImg);
                }

                ArrayList<LocalUserList> userLists = new ArrayList<>();

                for (MoreMoreGoodsInfoEntity.UserList item : entity.userList){
                    LocalUserList localUserList = new LocalUserList();
                    localUserList.attendTime = item.winningTime;
                    localUserList.userImage = item.userImage;
                    localUserList.userNickName = item.userNickName;
                    userLists.add(localUserList);
                }
                view.launchMoreMoreAction(productBanner, productBig, localMoreProductInfo, userLists, localWinner);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void moreOrderToDetail(int shareId) {
        MoreMoreGoodsInfoReq req = new MoreMoreGoodsInfoReq();
        req.drawId = shareId;
        model.moreOrderTpDetail(shareId, new HttpResultSubscriber<MoreMoreGoodsInfoEntity>() {
            @Override
            public void onSuccess(MoreMoreGoodsInfoEntity entity) {
                LocalMoreProductInfo localMoreProductInfo = new LocalMoreProductInfo();
                localMoreProductInfo.productId = entity.productId;
                localMoreProductInfo.productName = entity.productName;
                localMoreProductInfo.productStandard = entity.productStandard;
                localMoreProductInfo.restTime = entity.restTime;
                localMoreProductInfo.sharePath = entity.sharePath;
                localMoreProductInfo.shareCount = entity.shareCount;
                localMoreProductInfo.status = entity.status;
                localMoreProductInfo.drawNumber = entity.drawNumber;
                localMoreProductInfo.productPrice = entity.productPrice;
                localMoreProductInfo.relation = entity.relation;
                localMoreProductInfo.productSmallImage = entity.productSmallImage;
                localMoreProductInfo.productSubtitle = entity.productSubtitle;

                LocalWinner localWinner = new LocalWinner();
                localWinner.userId = entity.userId;
                localWinner.userImage = entity.userImage;
                localWinner.userNickName = entity.userNickName;
                localWinner.winningTime = entity.winningTime;
                localWinner.userNickName = entity.winnerUserNickName;
                localWinner.userImage = entity.winnerUserImage;
                localWinner.userId = entity.winnerUserId;


                ArrayList<ProductImages> productBanner = new ArrayList<>();

                for(MoreMoreGoodsInfoEntity.ProductImage item : entity.productImages){
                    ProductImages banner = new ProductImages();
                    banner.filePath = item.filePath;
                    productBanner.add(banner);
                }

                ArrayList<ProductImages> productBig = new ArrayList<>();

                for(MoreMoreGoodsInfoEntity.ProductBigImage item : entity.productBigImage){
                    ProductImages bigImg = new ProductImages();
                    bigImg.filePath = item.filePath;
                    productBig.add(bigImg);
                }

                ArrayList<LocalUserList> userLists = new ArrayList<>();

                for (MoreMoreGoodsInfoEntity.UserList item : entity.userList){
                    LocalUserList localUserList = new LocalUserList();
                    localUserList.attendTime = item.winningTime;
                    localUserList.userImage = item.userImage;
                    localUserList.userNickName = item.userNickName;
                    userLists.add(localUserList);
                }



                view.productResult(productBanner, productBig, localMoreProductInfo, userLists, localWinner);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void moreMoreOpen(Integer shareId) {
        model.moreMoreOpen(shareId, new HttpResultSubscriber<MoreMoreOpenEntity>() {
            @Override
            public void onSuccess(MoreMoreOpenEntity moreMoreOpenEntity) {
                view.openSuccess(moreMoreOpenEntity);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }
}
